/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.google.code.peersim.pastry.controls;

import com.google.code.peersim.pastry.protocol.PastryNode;
import com.google.code.peersim.pastry.protocol.PastryProtocol;
import peersim.core.Control;
import peersim.core.Network;

/**
 * This control class is in charge of asking {@link PastryNode}s to check for
 * sent messages waiting for pending acks. Messages that have not been acked
 * and whose time-out is expired must be properly handled by the {@link PastryProtocol}
 * instance.
 *
 * @author frusso
 * @version 0.1
 * @since 0.1
 */
public class PastryTimeoutTrigger implements Control {

  /**
   * Constructor.
   * 
   * @param prefix
   */
  public PastryTimeoutTrigger(String prefix) {
    // nop
  }

  /**
   * {@inheritDoc}
   *
   * Periodically invokes the {@link PastryProtocol#checkTimeouts()} method.
   */
  @Override
  public boolean execute() {
    boolean stop = false;
    int n = Network.size();
    for(int i=0; i<n; i++) {
      PastryNode node = (PastryNode) Network.get(i);
      node.checkTimeouts();
    }
    return stop;
  }
}